<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>信息列表</title>
</head>
<body>
<h1>学生修改信息页面</h1>

<form id="stuInfo" enctype="multipart/form-data">

    账号：<input id="username"><br/>
    姓名：<input type="text" name="name" id="name"/><br/>
    年龄：<input type="text" name="age" id="age"/><br/>
    性别：
    <input type="radio" name="sex" value="man" />男
    <input type="radio" name="sex" value="woman" />女
    <br/>
    爱好：
    <input type="checkbox" name="hobbies" value="football" />足球
    <input type="checkbox" name="hobbies" value="basketball" />篮球
    <input type="checkbox" name="hobbies" value="shop" />购物
    <br/>
    上传头像：<input type="file" name="photo"/><br/>

    <input type="submit" value="修改"/>
    <input type="button" value="返回" onclick="goIndex()"/>
</form>

<script src="js/jquery-1.8.2.js"></script>
<script type="text/javascript">
    function goIndex(){
        window.location = "index.html";
    }


    $(function (){
        $.ajax(
            {
                type:"post",
                url:"student?action=doInitModify",
                async:true,
                success:function (data){
                    const info = eval("("+data+")")
                    $("#username").val(info.username).attr("readonly","readonly")
                    $("#name").val(info.name)
                    $("#age").val(info.age)

                    $("input[name=sex]").each(function (){
                        if($(this).val() == info.sex){
                            $(this).attr("checked","checked")
                        }
                    })

                    $("input[name=hobbies]").each(function (){
                        if(info.hobbies.includes($(this).val())){
                            $(this).attr("checked","checked")
                        }
                    })
                }
            }
        )



        $("#stuInfo").submit(function (event){//修改功能

        })

    })

</script>

</body>
</html>